/**
 * 
 */
package com.thor.palmmall.rest.sales.input.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.KV;
import com.thor.commons.entity.UCN;
import com.thor.palmmall.rest.sales.input.ASalesInputQueryParam;
import com.thor.palmmall.spi.sales.input.SSalesInputQueryParam;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class SSalesInputQueryParamConverter
    implements Converter<ASalesInputQueryParam, SSalesInputQueryParam> {

  public static SSalesInputQueryParamConverter getInstance() {
    if (instance == null)
      instance = new SSalesInputQueryParamConverter();
    return instance;
  }

  private static SSalesInputQueryParamConverter instance;

  private SSalesInputQueryParamConverter() {
  }

  @Override
  public SSalesInputQueryParam convert(ASalesInputQueryParam source) {
    if (source == null)
      return null;

    SSalesInputQueryParam target = new SSalesInputQueryParam();
    target.setContracts(new ArrayList<UCN>());
    if (source.getContracts() != null)
      for (UCN sourceContract : source.getContracts())
        target.getContracts().add(UCN.newInstance(sourceContract));
    target.setPage(source.getPage());
    target.setPageSize(source.getPageSize());
    target.setStores(source.getStores());
    target.setUserGroups(new ArrayList<KV>());
    for (KV sourceUserGroup : source.getUserGroups())
      target.getUserGroups().add(KV.newInstance(sourceUserGroup));
    target.setOrder(source.getOrder());

    return target;
  }

}
